import uvicorn
from fastapi.middleware.cors import CORSMiddleware
import setproctitle
import app
from config import app_conf


if __name__ == '__main__':
    # 设置进程名称
    setproctitle.setproctitle('df-perception-backend')

    # 前端页面url
    origins = [
        "*"
    ]

    # 后台api允许跨域
    app.main_app.add_middleware(
        CORSMiddleware,
        allow_origins=origins,
        allow_credentials=False,
        allow_methods=["*"],
        allow_headers=["*"],
    )

    if app_conf.MODE == 'dev':
        uvicorn.run('app:main_app',
                    host=app_conf.HOST,
                    port=app_conf.PORT,
                    reload=True)
    elif app_conf.MODE == 'prod':
        uvicorn.run(app.main_app, host=app_conf.HOST, port=app_conf.PORT)
